********************************************************************************
********************************************************************************
* Table 5 & A1: Robustness
********************************************************************************
********************************************************************************

clear
use "$data/fdiff.dta", clear
set more off

* ANDERSON-RUBIN CI
ssc install twostepweakiv, replace
ssc install moremata, replace

********************************************************************************
* NET FISCAL CONTRIBUTIONS
********************************************************************************

global y1 	totnet_all_res_d
global y2 	totnet_excl_res_d
global w 	totpop13_wa

****global ctrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global ctrl c.feff#i.year c.sh_pgds#i.year c.sh_wap13#i.year ///
				 c.sh_college13#i.year c.sh_manuf13#i.year

* Using the shares from the 1993 census
qui ivreg2 $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store m1, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store m1_, title (IV1993)
	estadd local arci = e(ar_cset)

qui ivreg2 $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store m2, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store m2_, title (IV1993)
	estadd local arci = e(ar_cset)

* Normalizing ∆M by the local pop. in 2013
qui ivreg2 $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store m3, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store m3_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store m4, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store m4_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
* Using a distance-based instrument
qui ivreg2 $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store m5, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store m5_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store m6, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store m6_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
* Controlling for dynamic bias
sort area year
tsset area year
qui ivreg2 $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store m7, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]	// First stage F-stat for migch_fd
	estadd scalar Fstat2 = first[4,2]	// First stage F-stat for L.migch_fd
	qui twostepweakiv 2sls $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust small project(_all)
	estimates store m7_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
qui ivreg2 $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store m8, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar Fstat2 = first[4,2]
	qui twostepweakiv 2sls $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust small project(_all)
	estimates store m8_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
* LIML
qui ivreg2 $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store m9, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store m9_, title (LIML)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store m10, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store m10_, title (LIML)
	estadd local arci = e(ar_cset)
	
* Using individual pooled data
preserve
use "$data/fiscal.dta", clear
set more off

* KEEP NATIVES
drop if native==.

* DROP RURAL AREAS
drop if area ==.

* DEFLATE VARS
local vars totnet_all totnet_excl
foreach l of local vars{
replace `l' = `l' / deflactor
}

foreach l of local vars{
replace `l' = `l'/ 1000000
}

* TRIM
foreach l of local vars{
bys year: egen p1`l' = pctile(`l'), p(1)
bys year: egen p99`l' = pctile(`l'), p(99)
gen trim_`l' = 1 if `l'<=p1`l' | `l'>=p99`l'
replace trim_`l' = 0 if trim_`l'==.
drop p1`l' p99`l'
}

qui tab area, gen(area)

global indctrl sex age c.age#c.age educ
*global msactrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global msactrl c.feff#i.year c.sh_pgds#i.year

qui ivreg2 totnet_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totnet_all==0, cluster(area) first small partial(area2-area23)
	estimates store m11, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totnet_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totnet_all==0, cluster(area) small partial(area2-area23)
	estimates store m11_, title (Pooled)
	estadd local arci = e(ar_cset)
	
qui ivreg2 totnet_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totnet_excl==0, cluster(area) first small partial(area2-area23)
	estimates store m12, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totnet_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totnet_excl==0, cluster(area) small partial(area2-area23)
	estimates store m12_, title (Pooled)
	estadd local arci = e(ar_cset)
restore

* Tables
	// All budget - Appendix
esttab m1 m3 m5 m7 m9 m11, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("All budget: net fiscal cost")

esttab m1_ m3_ m5_ m7_ m9_ m11_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("All budget: net fiscal cost")

	// Restricted budget - Main text
esttab m2 m4 m6 m8 m10 m12, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("Restricted budget: net fiscal cost") 

esttab m2_ m4_ m6_ m8_ m10_ m12_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("Restricted budget: net fiscal cost") 

********************************************************************************
* REVENUES
********************************************************************************

* Using the shares from the 1993 census
global y1 	totrev_all_res_d
global y2 	totrev_excl_res_d
global w 	totpop13_wa

*global ctrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global ctrl c.feff#i.year c.sh_pgds#i.year c.sh_wap13#i.year ///
				 c.sh_college13#i.year c.sh_manuf13#i.year

qui ivreg2 $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store r1, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store r1_, title (IV1993)
	estadd local arci = e(ar_cset)

qui ivreg2 $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store r2, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store r2_, title (IV1993)
	estadd local arci = e(ar_cset)

* Normalizing ∆M by the local pop. in 2013
qui ivreg2 $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store r3, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store r3_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store r4, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store r4_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
* Using a distance-based instrument
qui ivreg2 $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store r5, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store r5_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store r6, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store r6_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
* Controlling for dynamic bias
sort area year
tsset area year
qui ivreg2 $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store r7, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]	// First stage F-stat for migch_fd
	estadd scalar Fstat2 = first[4,2]	// First stage F-stat for L.migch_fd
	qui twostepweakiv 2sls $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $fisctrl $msactrl i.year [aw=$w], robust small project(_all)
	estimates store r7_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
qui ivreg2 $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store r8, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar Fstat2 = first[4,2]
	qui twostepweakiv 2sls $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust small project(_all)
	estimates store r8_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
* LIML
qui ivreg2 $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store r9, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store r9_, title (LIML)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store r10, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store r10_, title (LIML)
	estadd local arci = e(ar_cset)
	
* Using individual pooled data
preserve
use "$data/fiscal.dta", clear
set more off

* KEEP NATIVES
drop if native==.

* DROP RURAL AREAS
drop if area ==.

* DEFLATE VARS
local vars totrev_all totrev_excl
foreach l of local vars{
replace `l' = `l' / deflactor
}

foreach l of local vars{
replace `l' = `l'/ 1000000
}

* TRIM
foreach l of local vars{
bys year: egen p1`l' = pctile(`l'), p(1)
bys year: egen p99`l' = pctile(`l'), p(99)
gen trim_`l' = 1 if `l'<=p1`l' | `l'>=p99`l'
replace trim_`l' = 0 if trim_`l'==.
drop p1`l' p99`l'
}

qui tab area, gen(area)

global indctrl sex age c.age#c.age educ
*global msactrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global msactrl c.feff#i.year c.sh_pgds#i.year

qui ivreg2 totrev_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totrev_all==0, cluster(area) first small partial(area2-area23)
	estimates store r11, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totrev_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totrev_all==0, cluster(area) small partial(area2-area23)
	estimates store r11_, title (Pooled)
	estadd local arci = e(ar_cset)
	
qui ivreg2 totrev_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totrev_excl==0, cluster(area) first small partial(area2-area23)
	estimates store r12, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totrev_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totrev_excl==0, cluster(area) small partial(area2-area23)
	estimates store r12_, title (Pooled)
	estadd local arci = e(ar_cset)
restore

* Tables
	// All budget - Appendix
esttab r1 r3 r5 r7 r9 r11, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("All budget: revenues")

esttab r1_ r3_ r5_ r7_ r9_ r11_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("All budget: revenues")

	// Restricted budget - Main text
esttab r2 r4 r6 r8 r10 r12, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("Restricted budget: revenues") 

esttab r2_ r4_ r6_ r8_ r10_ r12_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("Restricted budget: revenues") 

********************************************************************************
* EXPENDITURES
********************************************************************************

* Using the shares from the 1993 census
global y1 	totexp_all_res_d
global y2 	totexp_excl_res_d
global w 	totpop13_wa

*global ctrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global ctrl c.feff#i.year c.sh_pgds#i.year c.sh_wap13#i.year ///
				 c.sh_college13#i.year c.sh_manuf13#i.year

qui ivreg2 $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store g1, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store g1_, title (IV1993)
	estadd local arci = e(ar_cset)

qui ivreg2 $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust first small
	estimates store g2, title (IV1993)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = IV1993) $ctrl i.year [aw=$w], robust small
	estimates store g2_, title (IV1993)
	estadd local arci = e(ar_cset)

* Normalizing ∆M by the local pop. in 2013
qui ivreg2 $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store g3, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store g3_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store g4, title (Fix pop 2013)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd2 = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store g4_, title (Fix pop 2013)
	estadd local arci = e(ar_cset)
	
* Using a distance-based instrument
qui ivreg2 $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store g5, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y1 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store g5_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust first small
	estimates store g6, title (IV Distance)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls $y2 (migch_fd = distiv) $ctrl i.year [aw=$w], robust small
	estimates store g6_, title (IV Distance)
	estadd local arci = e(ar_cset)
	
* Controlling for dynamic bias
sort area year
tsset area year
qui ivreg2 $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store g7, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]	// First stage F-stat for migch_fd
	estadd scalar Fstat2 = first[4,2]	// First stage F-stat for L.migch_fd
	qui twostepweakiv 2sls $y1 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust small project(_all)
	estimates store g7_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
qui ivreg2 $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust first small
	estimates store g8, title (Dynamic)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	estadd scalar Fstat2 = first[4,2]
	qui twostepweakiv 2sls $y2 (migch_fd L.migch_fd = IV2005 L.IV2005) $ctrl i.year [aw=$w], robust small project(_all)
	estimates store g8_, title (Dynamic)
	estadd local arci = e(p1_lc_2sls_cset)
	estadd local arci2 = e(p2_lc_2sls_cset)
	
* LIML
qui ivreg2 $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store g9, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y1 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store g9_, title (LIML)
	estadd local arci = e(ar_cset)
	
qui ivreg2 $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust first small liml
	estimates store g10, title (LIML)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv liml $y2 (migch_fd = IV2005) $ctrl i.year [aw=$w], robust small
	estimates store g10_, title (LIML)
	estadd local arci = e(ar_cset)
	
* Using individual pooled data
preserve
use "$data/fiscal.dta", clear
set more off

* KEEP NATIVES
drop if native==.

* DROP RURAL AREAS
drop if area ==.

* DEFLATE VARS
local vars totexp_all totexp_excl
foreach l of local vars{
replace `l' = `l' / deflactor
}

foreach l of local vars{
replace `l' = `l'/ 1000000
}

* TRIM
foreach l of local vars{
bys year: egen p1`l' = pctile(`l'), p(1)
bys year: egen p99`l' = pctile(`l'), p(99)
gen trim_`l' = 1 if `l'<=p1`l' | `l'>=p99`l'
replace trim_`l' = 0 if trim_`l'==.
drop p1`l' p99`l'
}

qui tab area, gen(area)

global indctrl sex age c.age#c.age educ
*global msactrl feff sh_pgds sh_wap13 sh_college13 sh_manuf13
global msactrl c.feff#i.year c.sh_pgds#i.year

qui ivreg2 totexp_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totexp_all==0, cluster(area) first small partial(area2-area23)
	estimates store g11, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totexp_all (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totexp_all==0, cluster(area) small partial(area2-area23)
	estimates store g11_, title (Pooled)
	estadd local arci = e(ar_cset)
	
qui ivreg2 totexp_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totexp_excl==0, cluster(area) first small partial(area2-area23)
	estimates store g12, title (Pooled)
	matrix list e(first)					
	matrix first = e(first)
	estadd scalar Fstat = first[4,1]
	qui twostepweakiv 2sls totexp_excl (migch_pl = IV2005_pl) $indctrl $msactrl i.year area2-area23 [pw = fex12] if trim_totexp_excl==0, cluster(area) small partial(area2-area23)
	estimates store g12_, title (Pooled)
	estadd local arci = e(ar_cset)
restore

* Tables
	// All budget - Appendix
esttab g1 g3 g5 g7 g9 g11, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("All budget: expenditures")

esttab g1_ g3_ g5_ g7_ g9_ g11_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("All budget: expenditures")

	// Restricted budget - Main text
esttab g2 g4 g6 g8 g10 g12, keep(migch_fd migch_fd2 L.migch_fd migch_pl) ///
nostar b(3) se(3) coeflabels(migch_fd "∆M/L.POP" migch_fd2 "∆M/POP13" ///
L.migch_fd "L.∆M/L2.POP" migch_pl "M/POP13") ///
mlabels( , titles) collabels(none) obslast varwidth(20)  modelwidth(15) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L." ///
"Fstat F-stat" "Fstat2 F-stat lag") title("Restricted budget: expenditures") 

esttab g2_ g4_ g6_ g8_ g10_ g12_, keep() noobs mlabels( , titles) ///
collabels(none) obslast varwidth(20) modelwidth(20) ///
scalars("arci Anderson-Rubin CI" "arci2 Anderson-Rubin CI L.") ///
title("Restricted budget: expenditures") 


